<template>
	<view>
		<view class="form" v-if="Object.keys(userInfo).length > 0">
			<view class="item">
				<view class="lable">昵称</view>
				<view class="text">{{userInfo.nickName}}</view>
			</view>
			<view class="item">
				<view class="lable">性别</view>
				<view class="text">{{userInfo.sex == 0 ? '男' : userInfo.sex == 1 ? '女' : '未知'}}</view>
			</view>
			<view class="item">
				<view class="lable">角色</view>
				<view class="text">{{userInfo.roles[0].roleName || '未知'}}</view>
			</view>
			<view class="item">
				<view class="lable">部门</view>
				<view class="text">{{userInfo.dept.deptName || '未知'}}</view>
			</view>
			<view class="item">
				<view class="lable">手机号码</view>
				<view class="text">{{userInfo.phonenumber || '未知'}}</view>
			</view>
			<view class="item">
				<view class="lable">邮箱</view>
				<view class="text">{{userInfo.email || '未知'}}</view>
			</view>
			<view class="item">
				<view class="lable">登录IP</view>
				<view class="text">{{userInfo.loginIp || '未知'}}</view>
			</view>
		</view>
		<Loading v-else>
		</Loading>
		<view class="updata">
			<button @click="toProfile">修改资料</button>
			<button @click="toPassword">修改密码</button>
		</view>
		<button class="back" @click="goBack()">返回</button>
	</view>
</template>

<script>
	import Loading from '@/components/Loading/Loading.vue'
	import {
		getInfo
	} from '@/api/system/user'

	export default {
		components: {
			Loading
		},
		data() {
			return {
				userInfo:{}
			}
		},
		onShow() {
			this.getUserInfo();
			
		},
		methods: {
			// 获取用户信息
			getUserInfo() {
				const app = this
				getInfo().then(result => {
					app.userInfo = result.data.user
				})
			},
			toPassword() {
				uni.navigateTo({
					url: '/pages/mine/update/password'
				})
			},
			toProfile() {
				uni.navigateTo({
					url: '/pages/mine/update/profile'
				})
			},
			goBack() {
				uni.navigateBack({
					delta: 1
				});
			}
		}
	}
</script>

<style lang="scss" scoped>
	@import 'profile.scss';
</style>